using System;
using System.Collections.Generic;
using System.Text;
using Objects;

namespace DAL
{
    public class DALDangKy
    {
        public List<DangKy> GetAllItem()
        {
            List<DangKy> ListDangKy = new List<DangKy>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("DangKy_GetAllItem", sname, vname);

            DangKy Item = new DangKy();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListDangKy.Add((Item.Populate(dr)));
            }
            return ListDangKy;
        }

        public DangKy GetByIdKhachHang(int IdKhachHang)
        {
            DangKy Item = new DangKy();
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@IdKhachHang", "@Status" };
            string[] vname = new string[] { IdKhachHang.ToString(), Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("DangKy_GetByIdKhachHang", sname, vname);
            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

        public DangKy GetMaxId()
        {
            DangKy Item = new DangKy();
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("DangKy_GetMaxId", sname, vname);
            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

        public DangKy GetById(int Id)
        {
            DangKy Item = new DangKy();
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status", "@Id" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString(), Id.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("DangKy_GetById", sname, vname);
            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

        public DangKy GetByMaThanhToan(string MaThanhToan)
        {
            DangKy Item = new DangKy();
            try
            {
                
                clsDataAccess acc = new clsDataAccess();

                string[] sname = new string[] { "@Status", "@GetByMaThanhToan" };
                string[] vname = new string[] { Common.Myconst.HOATDONG.ToString(), MaThanhToan.ToString() };
                System.Data.DataSet ds = acc.CommandSelect("DangKy_GetByMaThanhToan", sname, vname);
                System.Data.DataRow dr = ds.Tables[0].Rows[0];
                return Item.Populate(dr);
            }
            catch {
                return Item = null;
            }
        }


        public int Insert(DangKy Item)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@IdKhachHang", "@IdKhachHangNhanThe", "@IdKhachHangNhanTheKhac", "@IdMauThe", "@IdLoaiThe", "@IdPhuongThucThanhToan", "@IdChiNhanh", "@IdMenhGia", "@IdMenhGiaKhac", "@SoLuong", "@NgayDangKy", "@NgayHetHan", "@NgayNhanThe","@MaThanhToan", "@GhiChu", "@Status", "@SapXep" };
            string[] vname = new string[] { Item.IdKhachHang.ToString(), Item.IdKhachHangNhanThe.ToString(), Item.IdKhachHangNhanTheKhac.ToString(), Item.IdMauThe.ToString(), Item.IdLoaiThe.ToString(), Item.IdPhuongThucThanhToan.ToString(), Item.IdChiNhanh.ToString(), Item.IdMenhGia.ToString(), Item.IdMenhGiaKhac.ToString(), Item.SoLuong.ToString(), Item.NgayDangKy.ToString(), Item.NgayHetHan.ToString(), Item.NgayNhanThe.ToString(),Item.MaThanhToan.ToString() , Item.GhiChu.ToString(), Common.Myconst.HOATDONG.ToString(), Item.SapXep.ToString() };
            return acc.InsertUpdateDetete("DangKy_Insert", sname, vname);

        }


        public int Update(DangKy Item)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Id", "@IdKhachHang", "@IdKhachHangNhanThe", "@IdKhachHangNhanTheKhac", "@IdMauThe", "@IdLoaiThe", "@IdPhuongThucThanhToan", "@IdChiNhanh", "@IdMenhGia", "@IdMenhGiaKhac", "@SoLuong", "@NgayDangKy", "@NgayHetHan", "@NgayNhanThe", "@GhiChu", "@Status", "@SapXep" };
            string[] vname = new string[] { Item.Id.ToString() ,Item.IdKhachHang.ToString(), Item.IdKhachHangNhanThe.ToString(), Item.IdKhachHangNhanTheKhac.ToString(), Item.IdMauThe.ToString(), Item.IdLoaiThe.ToString(), Item.IdPhuongThucThanhToan.ToString(), Item.IdChiNhanh.ToString(), Item.IdMenhGia.ToString(), Item.IdMenhGiaKhac.ToString(), Item.SoLuong.ToString(), Item.NgayDangKy.ToString(), Item.NgayHetHan.ToString(), Item.NgayNhanThe.ToString(), Item.GhiChu.ToString(), Common.Myconst.HOATDONG.ToString(), Item.SapXep.ToString() };
            return acc.InsertUpdateDetete("DangKy_Update", sname, vname);

        }

        public int Update_MaThanhToan(DangKy Item)
        {
            clsDataAccess acc = new clsDataAccess();
            string[] sname = new string[] { "@Id", "@MaThanhToan" };
            string[] vname = new string[] { Item.Id.ToString(), Item.MaThanhToan.ToString()};
            return acc.InsertUpdateDetete("DangKy_Update_MaThanhToan", sname, vname);

        }

    }
}